package com.jiot.controller.user;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jiot.controller.BaseController;

@Before(UserValidator.class)
public class LoginController extends BaseController {

	@Inject
	UserService userService;
	@Inject
	LoginService loginService;

	/**
	 * 账号是否已注册
	 * 
	 * @param account
	 */
	public void haveAccount(String account) {
		boolean haveAccount = userService.haveAccount(account);
		renderJson(Ret.ok("haveAccount", haveAccount));
	}

	/**
	 * 发送手机注册验证码
	 * 
	 * @param account
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public void sendPhoneCode(String phone) {
		Ret ret = loginService.getPhoneCode(phone);
		renderJson(ret);
	}

	/**
	 * 注册
	 * 
	 * @param account
	 * @param code
	 * @throws Exception
	 */
	public void register(String phone, String account, String code) throws Exception {
		Ret ret = loginService.register(phone, account, code);
		renderJson(ret);
	}

}
